home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / misc / sdf / cdf_rdwr.pro < prev    next >
Text File  |  1997-07-08  |  2KB  |  87 lines

  1. ;
  2. ;    Simple example #1
  3. ;
  4. ;    Save a matrix
  5. ;
  6. PRO MakeCDFData, filename
  7.  
  8.     ;    Check for a filename. Provide a default if none
  9.     ;    is given.
  10.     IF N_ELEMENTS(filename) EQ 0 THEN filename="cdf_example"
  11.  
  12.     ;    Remove any file(s) that might currently exist that
  13.     ;    would interfere with creating the new data.
  14.  
  15.     ON_IOERROR, NoFileToRemove
  16.     Id    = CDF_OPEN(Filename)
  17.     CDF_DELETE, Id
  18.  
  19.    NoFileToRemove:    
  20.  
  21.     ;    Create the CDF file. We need to specify the dimensions
  22.     ;    as part of the creation.
  23.     ;    By default the file created is ROW_MAJOR and has
  24.     ;    NETWORK_ENCODING
  25.  
  26.     Id    = CDF_CREATE(filename, [ 100, 200 ])
  27.  
  28.     ;    Create data to store
  29.     Data    = DIST(100,200)
  30.  
  31.     ;    Create a variable to hold the data that varies
  32.     ;    in both dimensions.
  33.  
  34.     VarId    = CDF_VARCREATE(Id,'MyData', ['VARY', 'VARY'], /CDF_FLOAT)
  35.  
  36.     ;    Create some attributes (to tell about our variable)
  37.  
  38.     dummy    = CDF_ATTCREATE(Id, "TITLE", /GLOBAL)
  39.     dummy    = CDF_ATTCREATE(Id, "UNITS", /VARIABLE)
  40.  
  41.     ;    Save the attributes for this particular variable
  42.  
  43.     CDF_ATTPUT, Id, "TITLE", 0, "X-Ray of my brain"
  44.     CDF_ATTPUT, Id, "UNITS", VarId, "Furlongs per Fortnight"
  45.  
  46.     ;    Write the data
  47.     CDF_VARPUT, Id, VarId, Data
  48.  
  49.     ;    Done
  50.     CDF_CLOSE, Id
  51. END
  52.  
  53. PRO ReadCDFData, filename
  54.  
  55.     ;    Open the file for reading
  56.     Id    = CDF_OPEN(filename)
  57.  
  58.     ;    Read in the Title. Note that we assume that
  59.     ;    the file will have a global attribute 'TITLE'
  60.     ;    with entry number 0 (pretty much the NSSDC standard --
  61.     ;    except we don't care how long the title is )
  62.     ;    This may not be the case in general but for
  63.     ;    our example, we assume it will be there
  64.  
  65.     CDF_ATTGET, Id, "TITLE", 0, Title
  66.  
  67.     ;    Read the data
  68.     CDF_VARGET, Id, 'MyData', Data
  69.  
  70.     ;    Now show our data with a title
  71.  
  72.     Print,'Displaying Data'
  73.     erase
  74.     loadct,2    ; choose a different colormap
  75.     TVSCL, Data
  76.     XYOUTS, !d.x_size/2, !d.y_size - 20, ALIGNMENT=0.5, /DEVICE, $
  77.         STRING(title)
  78.     CDF_CLOSE, Id
  79. END
  80.  
  81. PRO cdf_rdwr,Filename
  82.  
  83.     Print, 'Writing Data' & MakeCDFData,filename
  84.     Print, 'Reading Data' & ReadCDFData,filename
  85. END
  86.  
  87.